package com.xiaol.business.controller;

import com.xiaol.framework.properties.TeacherProperties;
import com.xiaol.framework.result.ResultUtil;
import com.xiaol.framework.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 两种方式：
 *      1.按照配置文件中的prefix读，读到一个bean里，例如：TeacherProperties
 *      2.一个一个读，读到自己的变量里，例如：userAdmin
 *      3.配置文件里也可以通过${}引用配置文件里的值，例如：content
 */
@RestController
@RequestMapping("/config")
public class ConfigController {

    @Autowired
    private TeacherProperties teacherProperties;

    @Value("${user.admin.name}")
    private String userAdmin;

    @Value("${content}")
    private String content;

    @RequestMapping("/readTeacherProperties")
    public Result<TeacherProperties> readTeacherProperties(){
        return ResultUtil.success(teacherProperties);
    }

    @RequestMapping("/readProperties")
    public String readProperties(){
        return userAdmin;
    }

    @RequestMapping("/readContent")
    public String readContent(){
        return content;
    }
}
